<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='../node_modules/react/umd/react.development.js'></script>
    <script src='../node_modules/react-dom/umd/react-dom.development.js'></script>
    <script src='../node_modules/babel-standalone/babel.min.js'></script>
    <script src='../node_modules/prop-types/prop-types.js'></script>
</head>

<body>
    <div id='root'></div>

    <script type='text/babel'>
        class MyCom extends React.Component {
            constructor(props) {
                super(props)

                /* 通过React.createRef()创建一个动态应用实例 令其指向某个DOM元素 */
                this.ref3 = React.createRef()
            }

            clickHandler = () => {
                console.log(this.refs.ref1.value);
                console.log(this.ref2.value);
                console.log(this.ref3.current.value);

                /* 设置value就是直接进行DOM操作 */
                /* 通过ref获取的DOM元素不受state控制——非受控组件 */
            }

            render() {
                return (
                    <div>
                        {/* 通过字符串获取DOM */}
                        <input type="text" ref="ref1" />
                        <button onClick={this.clickHandler}>获取用户输入</button>
                        <br />

                        {/* 通过回调函数（在ref对应的DOM元素加载完毕时回调）获取DOM */}
                        <input type="text" ref={el => this.ref2 = el} />
                        <button onClick={this.clickHandler}>获取用户输入</button>
                        <br />

                        {/* 通过React.createRef()创建一个动态应用实例 令其指向某个DOM元素 */}
                        <input type="text" ref={this.ref3} />
                        <button onClick={this.clickHandler}>获取用户输入</button>
                        <br />
                    </div>
                )
            }

        }
        
        ReactDOM.render(<MyCom />, document.getElementById('root'))
    </script>
</body>

</html>